// pages/pay/index.js
const App = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:null, //订单id
    orderDetail:null //订单详情
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options){
    this.setData({
      orderId:options.orderId
    })
    App.HttpService.orderDetail({
      
      id:this.data.orderId
    })
    .then(res=>{
      this.setData({
        orderDetail:res.data
      })
    })
  },

  //返回
  onReturn(){
    App.WechatService.redirectTo('/pages/index/index')
  },

  // 显示订单列表
  onShowOrderList(){
    App.WechatService.redirectTo('/pages/order/index')
  },

  //支付
  onPay(){
    let totalAmount=this.data.orderDetail.totalAmount
    let orderId=this.data.orderId
    let outTradeNo=this.data.orderDetail.orderCode
    App.HttpService.orderPay({
      totalFee:totalAmount,
      outTradeNo
    }).then(res=>{
      App.WechatService.requestPayment({
        timeStamp:res.timeStamp,
        nonceStr:res.nonceStr,
        package:res.package,
        signType:res.signType,
        paySign:res.paySign
      })
      .then((success)=>{
        App.WechatService.redirectTo('/pages/orderDetail/index?orderId='+orderId)
      },(error)=>{

      })
    })
  }

})